/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.api.model;

/**
 * Thrown by a registrar to indicate that the requested API version cannot be located.
 *
 * @author Tacoma Four
 */
public class NoSuchVersionException extends Exception
{
    private IQualifiedName qualifiedName;
    private IVersion version;

    /**
     * Thrown to indicate that the given version descriptor is not supported by the runtime environment.
     *
     * @param versionDescriptor Unsupported version descriptor
     */
    public NoSuchVersionException(IVersionDescriptor versionDescriptor)
    {
        this.qualifiedName = versionDescriptor.getQualifiedName();
        this.version = versionDescriptor.getVersion();
    }

    /**
     * Thrown to indicate that the given version descriptor is not supported by the runtime environment.
     *
     * @param versionDescriptor Unsupported version descriptor
     */
    public NoSuchVersionException(IVersionDescriptor versionDescriptor, String message)
    {
        super(message);
        this.qualifiedName = versionDescriptor.getQualifiedName();
        this.version = versionDescriptor.getVersion();
    }

    /**
     * Thrown to indicate that the given qualified name does not support the given API version.
     *
     * @param qualifiedName Qualified name that doesn't support the given version
     * @param version       Version unsupported by the qualified name
     */
    public NoSuchVersionException(IQualifiedName qualifiedName, IVersion version)
    {
        this.qualifiedName = qualifiedName;
        this.version = version;
    }

    /**
     * Thrown to indicate that no installed plugin supports the requested version.
     *
     * @param version Unsupported version
     */
    public NoSuchVersionException(IVersion version, String message)
    {
        super(message);
        this.version = version;
    }

    /**
     * Qualified name that doesn't support the given version
     *
     * @return Qualified name that doesn't support the given version, or null if no qualified name was specified
     */
    public IQualifiedName getQualifiedName()
    {
        return qualifiedName;
    }

    /**
     * Unsupported version.
     *
     * @return Version that was unsupported
     */
    public IVersion getVersion()
    {
        return version;
    }
}

